package app.dev.ems.web.wicket.factory;

import java.io.Serializable;

import org.apache.wicket.markup.html.link.Link;
import org.apache.wicket.model.Model;

import app.dev.ems.web.element.NavigationStatus;
import app.dev.ems.web.element.navigation.NavigationElement;
import app.dev.ems.web.wicket.page.admin.user.UserProfileSettingsPage;
import app.dev.ems.web.wicket.page.login.LoginPage;
import app.dev.ems.web.wicket.page.user.home.HomePage;
import app.dev.ems.web.wicket.page.user.profile.edit.ProfileEditPage;
import app.dev.ems.web.wicket.page.user.profile.search.ProfileSearchPage;
import app.dev.ems.web.wicket.page.user.profile.view.ProfileViewPage;
import app.dev.ems.web.wicket.session.EMSSession;

public enum NavigationLinkFactory {

	INSTANCE;
	
	private NavigationLinkFactory() {
		
	}
	
	public Link<Serializable> getUserHomeLink() {
		return new Link<Serializable>(NavigationElement.HOME.getElement(), new Model<Serializable>()) {
			
			private static final long serialVersionUID = 8462469015315393660L;

			@Override
			public void onClick() {
				EMSSession session = (EMSSession) getSession();
				session.setActiveHorizontalNavigationStatus(NavigationStatus.HOME);
				session.setActiveVerticalNavigationStatus(NavigationStatus.HOME);
				setResponsePage(HomePage.class);
			}
		};		
	}
	
	public Link<Serializable> getProfileLink() {
		return getProfileViewLink();
	}
	
	public Link<Serializable> getProfileViewLink() {
		return new Link<Serializable>(NavigationElement.PROFILE_VIEW.getElement(), new Model<Serializable>()) {
			
			private static final long serialVersionUID = -202078004891321909L;

			@Override
			public void onClick() {
				EMSSession session = (EMSSession) getSession();
				session.setActiveHorizontalNavigationStatus(NavigationStatus.PROFILE);
				session.setActiveVerticalNavigationStatus(NavigationStatus.PROFILE_VIEW);
				setResponsePage(ProfileViewPage.class);
			}
		};	
	}
	
	public Link<Serializable> getProfileEditLink() {
		return new Link<Serializable>(NavigationElement.PROFILE_EDIT.getElement(), new Model<Serializable>()) {
			
			private static final long serialVersionUID = 8973202169273090440L;

			@Override
			public void onClick() {
				EMSSession session = (EMSSession) getSession();
				session.setActiveHorizontalNavigationStatus(NavigationStatus.PROFILE);
				session.setActiveVerticalNavigationStatus(NavigationStatus.PROFILE_EDIT);
				setResponsePage(ProfileEditPage.class);
			}
		};	
	}
	
	public Link<Serializable> getProfileSearchLink() {
		return new Link<Serializable>(NavigationElement.POFILE_SEARCH.getElement(), new Model<Serializable>()) {

			private static final long serialVersionUID = -5611866817337989351L;

			@Override
			public void onClick() {
				EMSSession session = (EMSSession) getSession();
				session.setActiveHorizontalNavigationStatus(NavigationStatus.PROFILE);
				session.setActiveVerticalNavigationStatus(NavigationStatus.PROFILE_SEARCH);
				setResponsePage(ProfileSearchPage.class);
			}
		};	
	}
	
	public Link<Serializable> getLogoutLink() {
		return new Link<Serializable>(NavigationElement.LOGOUT.getElement(), new Model<Serializable>()) {
			
			private static final long serialVersionUID = 4058843245605799066L;

			@Override
			public void onClick() {
				((EMSSession) getSession()).invalidate();
				setResponsePage(LoginPage.class);
			}
		};
	}
	
	public Link<Serializable> getAdministrationLink() {
		return new Link<Serializable>(NavigationElement.ADMINISTRATION.getElement(), new Model<Serializable>()) {

			private static final long serialVersionUID = -854440075241056736L;

			@Override
			public void onClick() {
				EMSSession session = (EMSSession) getSession();
				session.setActiveHorizontalNavigationStatus(NavigationStatus.USER_ADMINISTRATION);
				session.setActiveVerticalNavigationStatus(NavigationStatus.USER_ADMINISTRATION);
				setResponsePage(UserProfileSettingsPage.class);
			}
		};
	}
	
	public Link<Serializable> getUserAdministrationLink() {
		return new Link<Serializable>(NavigationElement.USER_ADMINISTRATION.getElement(), new Model<Serializable>()) {

			private static final long serialVersionUID = -6511608630673101871L;

			@Override
			public void onClick() {
				EMSSession session = (EMSSession) getSession();
				session.setActiveHorizontalNavigationStatus(NavigationStatus.USER_ADMINISTRATION);
				session.setActiveVerticalNavigationStatus(NavigationStatus.USER_ADMINISTRATION);
				setResponsePage(UserProfileSettingsPage.class);
			}
		};
	}
}
